package com.zhq.okhttp;




import com.zhq.apputil.utils.LogUtil;
import com.zhq.okhttp.subscribe.HttpRequestListener;

import java.util.ArrayList;
import java.util.List;


/**
 * RxApi生命周期管理
 */
public class RxApiManager {
    private static final String TAG = RxApiManager.class.getSimpleName();
    private static RxApiManager sInstance = null;
    private List<HttpRequestListener> listListener;
    public static RxApiManager get() {
        if (sInstance == null) {
            synchronized (RxApiManager.class) {
                if (sInstance == null) {
                    sInstance = new RxApiManager();
                }
            }
        }
        return sInstance;
    }

    private RxApiManager() {
        listListener = new ArrayList<>();
    }

    /**
     * @param listener
     */
    public void add(HttpRequestListener listener) {
        listListener.add(listener);
    }

    /**
     * 清空所有listener
     **/
    public void clearAllListener() {
        if (listListener != null && listListener.size() > 0) {
            LogUtil.e(TAG, String.valueOf(listListener.size()));
            listListener.clear();
        }
    }

}
